import { Component, OnInit } from '@angular/core';
import { HttpRequest } from "../../../service/httpRequest";
import { flyIn } from '../../../animations/fly-in';

declare var $:any;
@Component({
  selector: 'app-competence',
  templateUrl: './competence.component.html',
  styleUrls: [
    './competence.component.css',
    '../../../../assets/css/bootstrap-treeview.min.css'],
  animations: [
    flyIn
  ]
})
export class CompetenceComponent implements OnInit {

  constructor(private httpRequest:HttpRequest) { }

  ngOnInit() {
    this.getData();
  }

  getData(){
    this.httpRequest.sendGet('actions/list').subscribe(res=>{
      let selectednodes = {};
      $('#treeview-checkable').treeview({
        data: res,
        showIcon: false,
        showCheckbox: false,
        onNodeChecked: function (event, node) {
          var selectednode = node.text;
          selectednodes[node.id] = selectednode;
        },

        onNodeUnchecked: function (event, node) {
          delete selectednodes[node.text];
        }

      });

      $('#treeview-checkable').treeview('collapseAll', {silent: true});
    },err => console.log(err));
  }
}
